from rest_framework.views import APIView
from apps.utils.responses import response_ok
from apps.utils.authentication import TokenAuthentication
from apps.orders.serializers import (
    PaymentSerializer,
)


class PayNotifyView(APIView):

    def post(self, request, *args, **kwargs):
        print(request.data)
        return response_ok({}, message='支付回调成功')


class PayOrderView(APIView):

    authentication_classes = (TokenAuthentication, )

    def post(self, request, *args, **kwargs):
        serializer = PaymentSerializer(data=request.data, context={'request': request})
        serializer.is_valid(raise_exception=True)
        return response_ok(serializer.save(), message='支付成功')
